package com.zyd.shiro.persistence.mapper;


import com.zyd.shiro.business.vo.AssetsConditionVO;
import com.zyd.shiro.business.vo.UserConditionVO;
import com.zyd.shiro.persistence.beans.PakAssets;
import com.zyd.shiro.persistence.beans.PakBorrowLine;
import com.zyd.shiro.persistence.beans.PakInventory;
import com.zyd.shiro.plugin.BaseMapper;
import com.zyd.shiro.framework.object.BaseConditionVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;


@Repository
public interface PakAssetsMapper extends BaseMapper<PakAssets> {

    /**
     * 分页查询
     *
     * @param vo
     * @return
     */
    @Select("<script>"+
            "SELECT s.* FROM PAK_ASSETS s WHERE  s.status != -2 " +
            " <if test = 'assets != null ' > " +
            "   <if test = 'assets.id != null ' > "+
            "     AND s.id = #{assets.id , jdbcType=BIGINT} " +
            "   </if> "+
            "   <if test = 'assets.status != null ' > "+
            "     AND s.status = #{assets.status , jdbcType=INTEGER" +
            "} " +
            "   </if> "+
            "   <if test = 'assets.categories != null ' > "+
            "     AND s.categories = #{assets.categories , jdbcType=INTEGER} " +
            "   </if> "+
            " </if> "+
            " GROUP BY s.id ORDER BY s.create_time DESC " +
            "</script>")
    List<PakAssets> findPageBreakByCondition(AssetsConditionVO vo);

    /**
     * 分页查询
     *
     * @param vo
     * @return
     */
    @Select("<script>"+
            "SELECT s.* FROM PAK_ASSETS s WHERE status !=-2 " +
            " <if test = 'assets != null ' > " +
            "   <if test = 'assets.status != null ' > "+
            "     AND s.status = #{assets.status , jdbcType=INTEGER" +
            "} " +
            "   </if> "+
            "   <if test = 'assets.user != null ' > "+
            "     AND s.user = #{assets.user , jdbcType=INTEGER" +
            "} " +
            "   </if> "+
            " </if> "+
            " GROUP BY s.id ORDER BY s.create_time DESC " +
            "</script>")
    List<PakAssets> listUser(AssetsConditionVO vo);


    @Select("<script>"+
            " SELECT s.* FROM PAK_ASSETS s WHERE status !=-2 " +
            "   <if test = 'org != 0'> "+
            "       AND s.org = #{org , jdbcType=BIGINT} " +
            "   </if > "+
            "   <if test = 'dept != 0' > "+
            "     AND s.dept = #{dept , jdbcType=BIGINT}" +
            "   </if >"+
            "   <if test = ' location != 0'>"+
            "      AND s.location = #{location , jdbcType=BIGINT}" +
            "   </if >"+
            "   <if test = ' status != 0'>"+
            "      AND s.status = #{status , jdbcType=INTEGER}" +
            "   </if >"+
            "   <if test = 'categories != 0'>"+
            "      AND s.categories = #{categories , jdbcType=BIGINT}" +
            "   </if >"+
            "   <if test = ' manager != 0'>"+
            "      AND s.manager = #{manager , jdbcType=BIGINT}" +
            "   </if >"+
            "   <if test = ' beginTime != null and finishTime !=null '>"+
            "     AND  ( s.ware_time BETWEEN #{beginTime , jdbcType=DATETIME} AND #{finishTime , jdbcType=DATETIME} )" +
            "   </if >"+
            " GROUP BY s.id ORDER BY s.create_time DESC " +
            "</script>")
    List<PakAssets> findByCondition(PakInventory pakInventory);

    @Select("<script>"+
            "SELECT s.* FROM PAK_ASSETS s WHERE `unicode` = #{code, jdbcType=VARCHAR}" +
            " GROUP BY s.id ORDER BY s.create_time DESC " +
            "</script>")
    PakAssets findByCode(String code);

    @Select("<script>"+
            "SELECT `status`,COUNT(*) AS num FROM pak_assets WHERE `user`= #{id,jdbcType=BIGINT} GROUP BY `status` ;" +
            "</script>")
    List<Map> groupByStatus(Long id);
}